package com.akeil.flash.preferences;

import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import com.akeil.flash.action.ReOpenSerialPortAction;
import com.akeil.flash.config.EDeviceType;
import com.akeil.flash.config.IConstantsConfig;

import flash.Activator;

public class LIMSPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage{
	private ComboFieldEditor method;
	private StringFieldEditor userName; // 用户名
	private StringFieldEditor passWord; // 密码框
	private StringFieldEditor testNumber; // 试样编号

	public LIMSPreferencePage(){
		super(GRID);
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
	}
	
	protected void createFieldEditors() {
		Composite parent = getFieldEditorParent();
        
		if(IConstantsConfig.deviceType == EDeviceType.MANUAL){
			method = new ComboFieldEditor(IPreferenceConstants.LIMS_METHOD, "分析方法", new String[][]{{"GB/T 261","GB/T 261"},{"GB/T 261_D","GB/T 261_D"}}, 
					parent);
		}else{
			method = new ComboFieldEditor(IPreferenceConstants.LIMS_METHOD, "分析方法", new String[][]{{"GB/T 3536","GB/T 3536"},{"GB/T 3536_D","GB/T 3536_D"}}, 
					parent);
		}
		
		
		addField(method);
		
		userName = new StringFieldEditor(IPreferenceConstants.LIMS_USERNAME, "LIMS用户名:", parent);
		addField(userName);
		
		passWord = new StringFieldEditor(IPreferenceConstants.LIMS_PASSWORD, "LIMS用户密码:", parent);
		addField(passWord);

		testNumber = new StringFieldEditor(IPreferenceConstants.LIMS_SAMPLENO, "样品编号:", parent);
		addField(testNumber);
	}

	@Override
	protected void performDefaults() {
		method.loadDefault();
		userName.loadDefault();
		passWord.loadDefault();
		testNumber.loadDefault();
	}

	@Override
	public boolean performOk() {
		boolean ret =  super.performOk();
		performApply();
		return ret;
	}

	@Override
	protected void performApply() {
		new ReOpenSerialPortAction().run();
	}

	@Override
	public void init(IWorkbench workbench) {
		// TODO Auto-generated method stub
		
	}

}
